package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.ui.activity.PhotoDetailsActivity;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.utils.ScreenUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/2.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class GamCirclePicAdapter extends RecyclerArrayAdapter<String> {
    public GamCirclePicAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new GamCirclePicHolder(parent);
    }

    public class GamCirclePicHolder extends BaseViewHolder<String> {


        @Bind(R.id.img)
        ImageView img;

        public GamCirclePicHolder(ViewGroup parent) {
            super(parent, R.layout.item_pic);
            ButterKnife.bind(this, itemView);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((ScreenUtils.getScreenWidth(BaseActivity.context) - DisplayUtil.dip2px(BaseActivity.context, 62)) / 4, (ScreenUtils.getScreenWidth(BaseActivity.context) - DisplayUtil.dip2px(BaseActivity.context, 62)) / 4);
            img.setLayoutParams(lp);

        }

        @Override
        public void setData(String data) {
            super.setData(data);
            Glide.with(BaseActivity.context)
                    .load(data)
                    .apply(MyApplication.options_no_transform)
                    .into(img);

            img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(BaseActivity.context, PhotoDetailsActivity.class);
                    intent.putExtra("img", (Serializable) getAllData());
                    intent.putExtra("position",getDataPosition());
                    BaseActivity.context.startActivity(intent);

                }
            });
        }
    }
}
